﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;
//using ZXing;
//using ZXing.QrCode;

//namespace xycn.common
//{
//    /// <summary>
//    /// 生成二维码
//    /// </summary>
//    public class QRCodeHelper
//    {
//        /// <summary>
//        /// 生成二维码
//        /// </summary>
//        /// <param name="text">The text.</param>
//        /// <param name="width">The width.</param>
//        /// <returns></returns>
//        public static System.Drawing.Image Create(string text, int width)
//        {
//            BarcodeWriter barcodeWriter = new BarcodeWriter();
//            barcodeWriter.Format = BarcodeFormat.QR_CODE;
//            QrCodeEncodingOptions qrCodeEncodingOptions = new QrCodeEncodingOptions();
//            qrCodeEncodingOptions.DisableECI = true;
//            qrCodeEncodingOptions.CharacterSet = "UTF-8";
//            qrCodeEncodingOptions.Width = width;
//            qrCodeEncodingOptions.Height = width;
//            qrCodeEncodingOptions.Margin = 1;
//            barcodeWriter.Options = qrCodeEncodingOptions;
//            System.Drawing.Bitmap bitmap = barcodeWriter.Write(text);
//            System.Drawing.Image result = System.Drawing.Image.FromHbitmap(bitmap.GetHbitmap());
//            bitmap.Dispose();
//            return result;
//        }

//        /// <summary>
//        /// 生成二维码
//        /// </summary>
//        /// <param name="text">The text.</param>
//        /// <param name="width">The width.</param>
//        /// <param name="height">The height.</param>
//        /// <returns></returns>
//        public static System.Drawing.Image Create(string text, string width, string height)
//        {
//            BarcodeWriter barcodeWriter = new BarcodeWriter();
//            barcodeWriter.Format = BarcodeFormat.QR_CODE;
//            QrCodeEncodingOptions qrCodeEncodingOptions = new QrCodeEncodingOptions();
//            qrCodeEncodingOptions.DisableECI = true;
//            qrCodeEncodingOptions.CharacterSet = "UTF-8";
//            qrCodeEncodingOptions.Width = Convert.ToInt32(width);
//            qrCodeEncodingOptions.Height = Convert.ToInt32(height);
//            qrCodeEncodingOptions.Margin = 1;
//            barcodeWriter.Options = qrCodeEncodingOptions;
//            System.Drawing.Bitmap bitmap = barcodeWriter.Write(text);
//            System.Drawing.Image result = System.Drawing.Image.FromHbitmap(bitmap.GetHbitmap());
//            bitmap.Dispose();
//            return result;
//        }

//        /// <summary>
//        /// 生成二维码 得到图片
//        /// </summary>
//        /// <param name="text">The text.</param>
//        /// <param name="width">The width.</param>
//        /// <param name="height">宽度</param>
//        /// <param name="saveFile">全路径</param>
//        /// <returns></returns>
//        public static bool Create(string text, string width, string height, string saveFile)
//        {
//            try
//            {
//                BarcodeWriter barcodeWriter = new BarcodeWriter();
//                barcodeWriter.Format = BarcodeFormat.QR_CODE;
//                QrCodeEncodingOptions qrCodeEncodingOptions = new QrCodeEncodingOptions();
//                qrCodeEncodingOptions.DisableECI = true;
//                qrCodeEncodingOptions.CharacterSet = "UTF-8";
//                qrCodeEncodingOptions.Width = Convert.ToInt32(width);
//                qrCodeEncodingOptions.Height = Convert.ToInt32(height);
//                qrCodeEncodingOptions.Margin = 1;
//                barcodeWriter.Options = qrCodeEncodingOptions;
//                System.Drawing.Bitmap bitmap = barcodeWriter.Write(text);
//                bitmap.Save(saveFile, System.Drawing.Imaging.ImageFormat.Png);
//                bitmap.Dispose();
//                return true;
//            }
//            catch (Exception)
//            {
//                return false;
//            }
//        }
//    }
//}
